package logic

import (
	"context"
	"math/rand"
	"time"
	"user3/model/redis"
	"user3/userrpc/internal/svc"
	"user3/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendsmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendsmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendsmsLogic {
	return &SendsmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendsmsLogic) Sendsms(in *userrpc.SendsmsRequest) (*userrpc.SendsmsResponse, error) {
	// todo: add your logic here and delete this line

	code := rand.Intn(9000) + 1000

	//sma, err := pkg.Sendsma(in.Tel, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//if *sma.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*sma.Body.Message)
	//}
	redis.Client.Set("sendsms"+in.Source+in.Tel, code, time.Minute*5)

	return &userrpc.SendsmsResponse{}, nil
}
